/**
 * Created by Administrator on 2020/3/3.
 */
import axios from 'axios'
import routerIndex from '../../router/index';

export default {
    post1: (requestHandler) => {
        axios.post(requestHandler.url, requestHandler.params, {       // 还可以直接把参数拼接在url后边
            headers: {
                'content-Type': 'application/json',
                'token': localStorage.getItem("token"),
            }
        }).then(function (res) {
            console.log(res);
            console.log(localStorage.getItem("token"));
            if (res.data.code == "401") {
                localStorage.removeItem("token");
                routerIndex.push({name: 'myzoe'});
                return false;
            }
            if (res.data.code == "220") {
                routerIndex.push({name: 'locked'})
            }
            requestHandler.success(res)
        }).catch(function (error) {
            if (error.response.data.code == 401) {
                localStorage.removeItem("token");
                routerIndex.push({name: 'myzoe'});
                return false;
            }
            if (error.response.data.code == 220) {
                routerIndex.push({name: 'locked'})
            }
            requestHandler.fail(error.response)
        })
    },
    postf: (requestHandler) => {
        axios.post(requestHandler.url, requestHandler.params, {       // 还可以直接把参数拼接在url后边
            headers: {
                'content-Type': 'application/json',
                'token': localStorage.getItem("token"),
            }
        }).then(function (res) {
            console.log(res,'.....');
            console.log(localStorage.getItem("token"));
            if (res.data.code == "401") {
                localStorage.removeItem("token");
                routerIndex.push({name: 'womaideliaoxq'})
                return false;
            }
            if (res.data.code == "220") {
                // routerIndex.push({name: 'locked'})
            }
            requestHandler.success(res)
        }).catch(function (error) {
            if (error.response.data.code == 401) {
                localStorage.removeItem("token");
                routerIndex.push({name: 'womaideliaoxq'})
                return false;
            }
            if (error.response.data.code == 220) {
                routerIndex.push({name: 'locked'})
            }
            requestHandler.fail(error.response)
        })
    },
    get1: (requestHandler) => {
        axios.get(requestHandler.url, {       // 还可以直接把参数拼接在url后边
            params: requestHandler.params,
            headers: {
                'content-Type': 'application/json',
                'token': localStorage.getItem("token"),
            }
        }).then(function (res) {
            if (res.data.code == "401") {
                localStorage.removeItem("token");
                routerIndex.push({name: 'myzoe'})
                return false;
            }
            requestHandler.success(res)
        }).catch(function (error) {
            if (error.response.data.code == "401") {
                localStorage.removeItem("token");
                routerIndex.push({name: 'myzoe'})
                return false;
            }
            requestHandler.fail(error.response)
        })
    },
    getf: (requestHandler) => {
        axios.get(requestHandler.url, {       // 还可以直接把参数拼接在url后边
            params: requestHandler.params,
            headers: {
                'content-Type': 'application/json',
                'token': localStorage.getItem("token"),
            }
        }).then(function (res) {
            if (res.data.code == "401") {
                localStorage.removeItem("token");
                routerIndex.push({name: 'myzoe'})
                return false;
            }
            requestHandler.success(res)
        }).catch(function (error) {
            if (error.response.data.code == "401") {
                localStorage.removeItem("token");
                routerIndex.push({name: 'myzoe'})
                return false;
            }
            requestHandler.fail(error.response)
        })
    }
}
